<?php

namespace app\admin\model\trades\assets;

use think\Model;


class Ordrelact extends Model
{

    

    

    // 表名
    protected $table = 'activity_order';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'paytime_text',
        'createTime_text',
        'utime_text',
        'paytype_text',
        'ordertype_text',
    ];



    //绑定成功
    public function getPaytypeList()
    {
        return ['2' => __('paytype 2'),'1' => __('paytype 1')];
    }
    //是否为默认绑定卡
    public function getOrdertypeList()
    {
        return ['0' => __('ordertype 0'),'1' => __('ordertype 1')];
    }

    //获取支付类型
    public function getPaytypeTextAttr($value, $data)
    {
        $value = $value ? $value : $data['paytype'];
        $list = $this->getPaytypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    //获取活动类型
    public function getOrdertypeTextAttr($value, $data)
    {
        $value = $value ? $value : $data['ordertype'];
        $list = $this->getOrdertypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }



    public function getPaytimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['paytime']) ? $data['paytime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getCreatetimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['createTime']) ? $data['createTime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getUtimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['utime']) ? $data['utime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setPaytimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setCreatetimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setUtimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


    public function activity()
    {
        return $this->belongsTo('app\admin\model\vactivities\Activity', 'activity_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
